---
title: Clear invalid person keyword syncs
summary: Clears keyword syncs whose person_id no longer exists before the unprocessed batch is retrieved.
status: draft
owner: Documents
last_reviewed: 2026-09-17
operation_id: OP-002
trigger: Step 4 of OP-001
---

# OP-002: Clear invalid person keyword syncs

Before the unprocessed batch is retrieved, the application clears any keyword syncs whose `person_id` no longer exists and logs one line per cleared record. The method name is misspelled in source (`ProcessInavlidPersonKeywordSyncs`) and is preserved verbatim here.

| Field | Value |
| --- | --- |
| **Operation ID** | OP-002 |
| **Trigger** | Step 4 of [OP-001](run-the-onbase-keyword-sync.md) |
| **Lifecycle stage** | Execute |
| **Owning component** | `OnBaseKeywordSyncRunner.ProcessInvalidKeywordSyncs` → `ImagingApiClient.ProcessInavlidPersonKeywordSyncs` |
| **Inputs** | None (remote API call with a null body) |
| **Outputs** | Server-side clear of invalid records; one log line per cleared record |
| **Failure exit code** | `5` — propagates from `OnBaseKeywordSyncRunner.Execute`'s catch block |

## Steps

1. `PUT ImageKeywordSyncs/ClearInvalidPersonUpdates` with a null body; take `.Results` ([BR-OBKS-002](../business-rules.md#br-obks-002-invalid-person-keyword-syncs-cleared-before-the-batch))
   - On failure: propagates → exit code `5`
2. For each returned `InvalidKeywordSync`, log `"Keyword sync id {KeywordSyncId} was not processed because the person_id {PersonId} did not exist.  Marked as processed."` ([BR-OBKS-002](../business-rules.md#br-obks-002-invalid-person-keyword-syncs-cleared-before-the-batch))
   - Whether the Imaging API's `ClearInvalidPersonUpdates` also marks records processed server-side is asserted by the log text but no client-side mark call follows*

## Process flow

The following diagram visualizes this operation's control flow.

```mermaid
flowchart TD
    A["PUT ImageKeywordSyncs/<br>ClearInvalidPersonUpdates"] --> B{"Any records<br>returned?"}
    B -->|Yes| C["Log one line per<br>InvalidKeywordSync record"]
    B -->|No| D["Continue - nothing to log"]
    C --> E["Return to OP-001"]
    D --> E
    A -.->|Exception| ERR["Exit code 5"]
```

## Logging

| Log id | Written content |
| --- | --- |
| Not application-assigned (fans out to all registered `file0`–`file4` writers) | `"Keyword sync id {id} was not processed because the person_id {personId} did not exist.  Marked as processed."` per cleared record |

## Error handling
- Any exception from the `PUT` call propagates to `OnBaseKeywordSyncRunner.Execute`'s catch block, which logs and rethrows → exit code `5`.

## Related documentation
- [Run lifecycle](../run-lifecycle.md)
- [Operations and processes](../operations-processes.md)
- [Business rules](../business-rules.md)
- [Operational runbook](../operational-runbook.md)

> **Note:** Statements marked with `*` were inferred from code structure, naming conventions, or contextual evidence where direct confirmation was not available in source artifacts.

## Sources
- `OnBaseKeywordSync/OnBaseKeywordSyncRunner.cs`
- `OnBaseKeywordSync/Services/ImagingApiClient.cs`
- `OnBaseKeywordSync/Contracts/InvalidKeywordSync.cs`
